﻿using EnetaMvc.ApplicationServices.Dto;
using System.Web;

namespace EnetaMvc.Web.Extensions
{
    public static class ProfileExtensions
    {
        public static bool CanShowDescriptionBlock(this FullProfileDto profile)
        {
            return CanShowDescription(profile) || CanShowHomePage(profile);
        }
        public static bool CanShowDescription(this FullProfileDto profile)
        {
            return !string.IsNullOrEmpty(profile.Description);
        }
        public static bool CanShowHomePage(this FullProfileDto profile)
        {
            return !string.IsNullOrEmpty(profile.HomePage);
        }

        public static bool CanShowEducationBlock(this FullProfileDto profile)
        {
            return CanShowSchool(profile) || CanShowFieldOfStudy(profile);
        }
        public static bool CanShowSchool(this FullProfileDto profile)
        {
            return profile.ShowSchool && !string.IsNullOrEmpty(profile.School);
        }
        public static bool CanShowFieldOfStudy(this FullProfileDto profile)
        {
            return profile.ShowFieldOfStudy && !string.IsNullOrEmpty(profile.FieldOfStudy);
        }

        public static bool CanShowJobBlock(this FullProfileDto profile)
        {
            return CanShowCompany(profile) || CanShowJobTitle(profile);
        }
        public static bool CanShowCompany(this FullProfileDto profile)
        {
            return profile.ShowCompany && !string.IsNullOrEmpty(profile.Company);
        }
        public static bool CanShowJobTitle(this FullProfileDto profile)
        {
            return profile.ShowJobTitle && !string.IsNullOrEmpty(profile.JobTitle);
        }

        public static bool CanEditProfile(this FullProfileDto profile)
        {
            var context = HttpContext.Current;
            if (context == null)
                return false;

            if (!context.User.Identity.IsAuthenticated)
                return false;

            return (context.User.Identity.Name == profile.LiveIdToken);
        }
    }
}